# unittests for TarjanController

import unittest
from TarjanObservable import TarjanObservable
from TarjanMap import TarjanMap
from TarjanController import TarjanController

class FakeView(TarjanObservable):
    cursor_direction = 0
    cursor_pos = (0,0)
    def attach(self, dummy):
        pass
    def update(self, x, y, w, h):
        pass

class resizeTest(unittest.TestCase):
    def setUp(self):
        map = TarjanMap(10, 10)
        for cell in [map.getCell(x,y) for y in xrange(map.height) for x in xrange(map.width)]:
            cell.floor = str((cell.x, cell.y))
        self.controller = TarjanController(FakeView(), map)

    def testResizeToSmaller(self):
        "resizing to smaller mapsize should work"
        self.controller.ResizeMap(5,6)
        self.assertEqual( self.controller.map.width, 5 )
        self.assertEqual( self.controller.map.height, 6 )
        for cell in [self.controller.map.getCell(x,y) for y in xrange(self.controller.map.height) for x in xrange(self.controller.map.width)]:
            self.assertEqual( str((cell.x, cell.y)), cell.floor )

    def testResizeToLarger(self):
        "resizing to larger mapsize should work"
        self.controller.ResizeMap(20,20)
        self.assertEqual( self.controller.map.width, 20 )
        self.assertEqual( self.controller.map.height, 20 )
        for cell in [self.controller.map.getCell(x,y) for y in xrange(10) for x in xrange(10)]:
            self.assertEqual( str((cell.x, cell.y)), cell.floor )
        for cell in [self.controller.map.getCell(x,y) for y in xrange(10,20) for x in xrange(10,20)]:
            self.assertEqual( '', cell.floor )

        

        
